Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: SelectionList multiple selection #22622

Merged

Conversation

thiagobrez
Copy link
Contributor

@thiagobrez thiagobrez commented Jul 11, 2023

Details

Phase 2 of 3, regarding selection lists refactor. Tracker issue: #11795

This PR iterates on Phase 1 by extending SelectionListRadio to also be able to handle multiple selection lists, since both would share all the basics such as keyboard listeners, safe area, layout calculation, focus and scrolling.

Following pages were changed:

  • WorkspaceMembersPage
  • WorkspaceInvitePage

The tracker issue also outlined pages to create a new group and split money, but it was decided that it's best if we don't touch those for now, as things are still getting figured out.

  • SelectionListRadio and all related files were renamed to SelectionList

  • SelectionList now accepts the following new props:

    • canSelectMultiple: changes the rendered item to be the newly created CheckboxListItem
    • onSelectAll: callback to fire when the "Select All" checkbox is pressed
    • onDismissError: callback to fire when an error is dismissed
  • SelectionList now renders a section header if provided in section.title

  • Created a formatMemberForList in OptionsListUtils to format a personalDetails or userToInvite to the correct format accepted by SelectionList. Previously, those gigantic objects were being passed down to the list and only a few properties were being used, this way it's clear what properties an item needs to have

    • Note: did not change the existing OptionsListUtils.getMemberInviteOptions directly because it's a big logic and still being used by the lists that are not refactored yet
  • Added new Storybook stories for the new list variations

  • Added new Reassure performance tests for the new list variations, and also a case for scrolling the list

Fixed Issues

$ #20353

Tests

  • Verify that no errors appear in the JS console
  • Verify that no regressions appeared in the Timezone, Pronouns, Year Picker, Language and Priority Mode lists
  • Verify that the Workspace Members and Workspace Invite Members pages are working as expected

Offline tests

QA Steps

  • Verify that no errors appear in the JS console
  • Verify that no regressions appeared in the Timezone, Pronouns, Year Picker, Language and Priority Mode lists
  • Verify that the Workspace Members and Workspace Invite Members pages are working as expected

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web - Chrome
web.chrome.mov
Web - Safari
web.safari.mov
Mobile Web - Chrome
android.web.mov
Mobile Web - Safari
ios.web.mp4
Desktop
desktop.mov
iOS
ios.native.mp4
Android
android.native.mov

@thiagobrez thiagobrez changed the title Refactor/selection list/checkbox list refactor: SelectionList multiple selection Jul 11, 2023
src/components/SelectionList/BaseSelectionList.js Outdated Show resolved Hide resolved
src/components/SelectionList/BaseSelectionList.js Outdated Show resolved Hide resolved
src/components/SelectionList/CheckboxListItem.js Outdated Show resolved Hide resolved
src/components/SelectionList/CheckboxListItem.js Outdated Show resolved Hide resolved
src/components/SelectionList/BaseSelectionList.js Outdated Show resolved Hide resolved
src/components/SelectionList/index.android.js Show resolved Hide resolved
src/components/SelectionList/index.ios.js Show resolved Hide resolved
src/components/SelectionList/index.js Show resolved Hide resolved
Copy link
Contributor

@rezkiy37 rezkiy37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, left a couple comments.

@roryabraham
Copy link
Contributor

Bit of feedback here – to merge a PR of this size and scope without any test or QA steps listed in the PR description is frankly unacceptable. Can we please add a thorough list of QA steps for Applause to follow to QA this on staging?

@roryabraham
Copy link
Contributor

Also, this PR is associated with a regression on staging

@cristipaval
Copy link
Contributor

Bit of feedback here – to merge a PR of this size and scope without any test or QA steps listed in the PR description is frankly unacceptable. Can we please add a thorough list of QA steps for Applause to follow to QA this on staging?

Thanks for the feedback @roryabraham! There are tests added to the PR description
Screenshot 2023-08-25 at 12 42 09

I do agree that those tests could be improved, but I also think we should first figure out how we could know the product specs better, what is that single source of truth based on which we know the expectations and lay them down thoroughly in a list of tests. In this specific case, the tests mentioned the features that were impacted by the PR and we expected the QA team to run all test cases that they have for those features.

@roryabraham
Copy link
Contributor

roryabraham commented Aug 25, 2023

Great response @cristipaval! To answer your questions/concerns:

  • the single source of truth for our regression test suite is TestRail. Regression tests are organized by feature / component. Expensify employees have access to that and can pull the regression tests from there
  • If you're doing a big refactor, you can run an AdHoc test build and then ask Applause to run a full or partial regression test run on your feature branch before it's merged to main. This is a bit time-consuming and expensive so in general we should limit how often we do this, but there are some times where it's a great choice. For example, we've done it several times for the PR to enable the new React Native architecture. We also did this when we were refactoring our whole navigation stack. In both those cases, the changes were very global and breaking up the PR into smaller PRs wasn't necessarily a viable option
  • (bit of good news) Applause is going to start investing a good amount of time into automating parts of the regression suite with E2E tests. I think these tests may end up taking too long to run on every PR (we'll see...), but those will definitely help to give us more confidence to ship features with better stability.
  • Last thing I'll hold out is that we can opt to use betas. A deploy blocker behind a beta is not a deploy blocker. Not sure I would've done that for this particular project but in general it's very helpful and allows your feature to go through its own set of growing pains without disrupting other features from being shipped.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/cristipaval in version: 1.3.58-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.3.57-6 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.3.58-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@aldo-expensify
Copy link
Contributor

Bug zero: This PR caused this regression: #25859

image

Taken from: #25859 (comment)

Comment on lines +177 to +202
const selectRow = (item, index) => {
// In single-selection lists we don't care about updating the focused index, because the list is closed after selecting an item
if (canSelectMultiple) {
if (sections.length === 1) {
// If the list has only 1 section (e.g. Workspace Members list), we always focus the next available item
const nextAvailableIndex = _.findIndex(flattenedSections.allOptions, (option, i) => i > index && !option.isDisabled);
setFocusedIndex(nextAvailableIndex);
} else {
// If the list has multiple sections (e.g. Workspace Invite list), we focus the first one after all the selected (selected items are always at the top)
const selectedOptionsCount = item.isSelected ? flattenedSections.selectedOptions.length - 1 : flattenedSections.selectedOptions.length + 1;
setFocusedIndex(selectedOptionsCount);
}
}

onSelectRow(item);
};

const selectFocusedOption = () => {
const focusedOption = flattenedSections.allOptions[focusedIndex];

if (!focusedOption || focusedOption.isDisabled) {
return;
}

selectRow(focusedOption, focusedIndex);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auto highlight feature is only meant for keyboard navigation right? On click/press we shouldn't highlight any element as this is causing a regression #27377.

We are going to limit that feature to keyboard navigation only on #27646. Let us know if you think we shouldn't.

cc @thiagobrez @Santhosh-Sellavel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @s77rt ! This was already fixed here, waiting for a final approval: #27246

</View>
</PressableWithFeedback>
)}
<SectionList
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #26243:
This refactor caused minor inconsistency with OptionsList.
stickySectionHeadersEnabled prop is enabled by default in SectionList.
OptionsList disabled it but SelectionList from this PR didn't.

keyboardType={keyboardType}
selectTextOnFocus
spellCheck={false}
onSubmitEditing={selectFocusedOption}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blurOnSubmit prop could be passed here to be consistent with BaseOptionsSelector behavior.
Issue: #28072

result.push({
keyForList: accountID,
isSelected: _.contains(selectedEmployees, Number(accountID)),
isDisabled: accountID === props.session.accountID || details.login === props.policy.owner || policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accountID should have been converted to a Number before matching. This caused #28539

@shubham1206agra
Copy link
Contributor

This PR caused conflicting listeners with ConfirmModal, which caused #33201.

result.push({
keyForList: accountID,
isSelected: _.contains(selectedEmployees, Number(accountID)),
isDisabled: accountID === props.session.accountID || details.login === props.policy.owner || policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the isDisabled check contributed to creating the following issue:

but since the transition from optimistic local data to real BE returned data wasn't tested when this PR was merged -> it wasn't reported as an issue until recently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.